/**
 * @ Author 何涛
 * @ Date 2016/03/05 11:31:24
 */

if (typeof tyNamespace.JumpType == "undefined") {
    tyNamespace.JumpType = {};
    tyNamespace.JumpType.ChangeVoice = 0;
    tyNamespace.JumpType.MyProp = 1;
    tyNamespace.JumpType.MyPropUseable = 2;
    tyNamespace.JumpType.MailAllDelete = 3;
    tyNamespace.JumpType.MailAllGet = 4;
    tyNamespace.JumpType.Feedback = 5;
    tyNamespace.JumpType.Feedbackfailed = 5.2;
    tyNamespace.JumpType.BuyNew = 6;
    tyNamespace.JumpType.BuyOne = 7;
    tyNamespace.JumpType.ShopSW = 8;
    tyNamespace.JumpType.ShopSWOK = 9;
    tyNamespace.JumpType.UsePropFail = 10;
    tyNamespace.JumpType.UseLaba = 11;
    tyNamespace.JumpType.UseXuezhan = 12;
    tyNamespace.JumpType.Qszb = 13;
    tyNamespace.JumpType.KickOff = 14;
    tyNamespace.JumpType.OtherLog = 15;
    tyNamespace.JumpType.Block = 16;
    tyNamespace.JumpType.Offline = 17;
    tyNamespace.JumpType.Xuezhan = 18;
    tyNamespace.JumpType.Limit = 19;//限制分
    tyNamespace.JumpType.Match = 20;//兑换券关闭时
    tyNamespace.JumpType.BxVIP = 21;//包厢没有vip
    tyNamespace.JumpType.BxGOLD = 22;//包厢金币不足
}

if (typeof tyNamespace.WarnType == "undefined") {
    tyNamespace.WarnType = {};
    tyNamespace.WarnType.Gold = 0;
    tyNamespace.WarnType.Diamond = 1;
    tyNamespace.WarnType.Voucher = 2;
    tyNamespace.WarnType.Pochan = 3;
    tyNamespace.WarnType.Limit = 4;
    tyNamespace.WarnType.PochanJifen = 5;
}

if (typeof tyNamespace.PriceType == "undefined") {
    tyNamespace.PriceType = {};
    tyNamespace.PriceType.Gold = 0;
    tyNamespace.PriceType.Diamond = 1;
    tyNamespace.PriceType.Voucher = 2;
}

if (typeof tyNamespace.MissionType == "undefined") {
    tyNamespace.MissionType = {};
    tyNamespace.MissionType.Gold = 0;
    tyNamespace.MissionType.Prop = 1;
}

tyNamespace.JumpLayer = tyNamespace.ModelLayer.extend({
    type: null,
    callback: null,
    target: null,
    args: [],
    background: null,
    backgroundSize:null,

    ctor: function (type, callback, target, args) {
        this._super();

        this.type = type;
        this.callback = callback;
        this.target = target;
        if (args != undefined)
            this.args = args;
    },

    onEnter: function () {
    	this._super();
    	cc.spriteFrameCache.addSpriteFrames(gpNamespace.warningRes.Warning_plist);
    	cc.spriteFrameCache.addSpriteFrames(gpNamespace.pdkTanKuangRes.tankuang_plist);
    	cc.spriteFrameCache.addSpriteFrames(gpNamespace.pdkgameTweenRes.game_tween_plist);

        //弹出框背景
    	var background = new cc.Sprite(gpNamespace.tankuang.background);//tyNamespace.notice.Jump_background
        background.attr({
            x: cc.winSize.width / 2,
            y: cc.winSize.height / 2
        });
        this.addChild(background);
        this.background = background;
        this.backgroundSize = background.getContentSize();
        //content
        switch (this.type) {
            case tyNamespace.JumpType.ChangeVoice:
                var label = new cc.LabelTTF("您已经修改过角色发音。", "Arial", 30);
                label.attr({
                    x: this.backgroundSize.width / 2,
                    y: 200
                });
                background.addChild(label);

                this.addOneMenu();

                break;

            case tyNamespace.JumpType.MyProp:
                this.addOneMenu();
                break;

            case tyNamespace.JumpType.MyPropUseable:
                var sprite = new cc.Sprite(tyNamespace.notice.Jump_myProp);
                sprite.attr({
                    x: this.backgroundSize.width / 2,
                    y: 250
                });
                background.addChild(sprite);

                this.addTwoMenu();

                break;

            case tyNamespace.JumpType.MailAllDelete:
                var sprite = new cc.Sprite(tyNamespace.notice.Jump_allDelete);
                sprite.attr({
                    x: this.backgroundSize.width / 2,
                    y: 200
                });
                background.addChild(sprite);

                this.addTwoMenu();

                break;

            case tyNamespace.JumpType.MailAllGet:
                var sprite = new cc.Sprite(tyNamespace.notice.Jump_allGet);
                sprite.attr({
                    x: this.backgroundSize.width / 2,
                    y: 200
                });
                background.addChild(sprite);

                this.addTwoMenu();

                break;

            case tyNamespace.JumpType.Feedback:
                var label = new cc.LabelTTF("反馈成功！", "Arial", 30);
                label.attr({
                    x: this.backgroundSize.width / 2,
                    y: 200
                });
                background.addChild(label);

                this.addOneMenu();

                break;

            case tyNamespace.JumpType.Feedbackfailed:
            	var label = new cc.LabelTTF("请输入正确的手机号！", "Arial", 30);
            	label.attr({
            		x: this.backgroundSize.width / 2,
            		y: 200
            	});
            	background.addChild(label);

            	this.addOneMenu();

                break;

            case tyNamespace.JumpType.BuyNew:
                var label = new cc.LabelTTF("您已经购买过新手大礼包。", "Arial", 30);
                label.attr({
                    x: this.backgroundSize.width / 2,
                    y: 200
                });
                background.addChild(label);

                this.addOneMenu();

                break;

            case tyNamespace.JumpType.BuyOne:
                var label = new cc.LabelTTF("您已经购买过超值大礼包。", "Arial", 30);
                label.attr({
                    x: this.backgroundSize.width / 2,
                    y: 200
                });
                background.addChild(label);

                this.addOneMenu();

                break;

            case tyNamespace.JumpType.ShopSW:
                var label = new cc.LabelTTF("确认用 " + this.args[1] + " 兑换券，兑换", "Arial", 25);
                label.attr({
                    x: this.backgroundSize.width / 2,
                    y: 240
                });
                background.addChild(label);

                var label1 = new cc.LabelTTF(this.args[2], "Arial", 25);
                label1.attr({
                    x: this.backgroundSize.width / 2,
                    y: 210
                });
                background.addChild(label1);

                this.addTwoMenu();

                break;

            case tyNamespace.JumpType.ShopSWOK:
                var sprite = new cc.Sprite(tyNamespace.notice.Jump_swOK);
                sprite.attr({
                    x: this.backgroundSize.width / 2,
                    y: 200
                });
                background.addChild(sprite);

                this.addOneMenu();

                break;

            case tyNamespace.JumpType.UsePropFail:
                var label = new cc.LabelTTF("您目前无法使用该道具。", "Arial", 30);
                label.attr({
                    x: this.backgroundSize.width / 2,
                    y: 200
                });
                background.addChild(label);

                this.addOneMenu();

                break;

            case tyNamespace.JumpType.UseLaba:
                var sprite = new cc.Sprite(tyNamespace.notice.Jump_useLaba);
                sprite.attr({
                    x: this.backgroundSize.width / 2,
                    y: 200
                });
                background.addChild(sprite);

                this.addTwoMenu();

                break;

            case tyNamespace.JumpType.Qszb:
                var label = new cc.LabelTTF("您的参赛券不够。", "Arial", 30);
                label.attr({
                    x: this.backgroundSize.width / 2,
                    y: 200
                });
                background.addChild(label);

                this.addOneMenu();

                break;

            case tyNamespace.JumpType.KickOff:
                var sprite = new cc.Sprite(tyNamespace.notice.Jump_kickOff);
                sprite.attr({
                    x: this.backgroundSize.width / 2,
                    y: 200
                });
                background.addChild(sprite);

                this.addKickMenu();

                break;

            case tyNamespace.JumpType.OtherLog:
                var sprite = new cc.Sprite(tyNamespace.notice.Jump_otherLog);
                sprite.attr({
                    x: this.backgroundSize.width / 2,
                    y: 200
                });
                background.addChild(sprite);

                this.addKickMenu();

                break;

            case tyNamespace.JumpType.Block:
                var sprite = new cc.Sprite(tyNamespace.notice.Jump_block);
                sprite.attr({
                    x: this.backgroundSize.width / 2,
                    y: 200
                });
                background.addChild(sprite);

                this.addKickMenu();

                break;

            case tyNamespace.JumpType.Offline:
            	var sprite = new cc.Sprite(gpNamespace.warning.Warning_Sentence20);
                sprite.attr({
                    x: this.backgroundSize.width / 2,
                    y: 200
                });
                background.addChild(sprite);

                this.addKickMenu();

                break;

            case tyNamespace.JumpType.Xuezhan:
                var sprite = new cc.Sprite(tyNamespace.notice.Jump_useXuezhan);
                sprite.attr({
                    x: this.backgroundSize.width / 2,
                    y: 200
                });
                background.addChild(sprite);

                this.addTwoMenu();

                break;

            case tyNamespace.JumpType.Limit:
            	var currentGold = userInfo.gold;

                cc.log("gpNamespace.LoginInfo.GOLD:" + gpNamespace.LoginInfo.GOLD);
                var limitGold;
                var index = this.args[0];
                if (index == undefined) {
                    switch (tyNamespace.subRoom) {
                        case 1:
                            limitGold = gpNamespace.RuchangInfo.RUCHANGDATA[0][1];
                            break;
                        case 2:
                            limitGold = gpNamespace.RuchangInfo.RUCHANGDATA[1][1];
                            break;
                        case 3:
                            limitGold = gpNamespace.RuchangInfo.RUCHANGDATA[2][1];
                            break;
                        case 4:
                            limitGold = gpNamespace.RuchangInfo.RUCHANGDATA[3][1];
                            break;
                    }
                }
                else {
                    limitGold = gpNamespace.RuchangInfo.RUCHANGDATA[index][1];
                }
                var restGold = Math.abs(parseInt(currentGold) - parseInt(limitGold));
                //信息1
                var labelText = "您还差" + restGold + "金币,";
                var label1 = new cc.LabelTTF(labelText, "Arial", 28);
                label1.setFontFillColor(cc.color(33, 66, 99, 255));
                label1.attr({
                	x: this.backgroundSize.width / 2,
                    y: 230
                });
                background.addChild(label1);

                //信息2
                var labelText2 = "才能进入游戏！";
                var label2 = new cc.LabelTTF(labelText2, "Arial", 28);
                label2.setFontFillColor(cc.color(33, 66, 99, 255));
                label2.attr({
                	x: this.backgroundSize.width / 2,
                    y: 190
                });
                background.addChild(label2);

                this.addOneMenu();

                break;

            case tyNamespace.JumpType.Match:
                var sprite = new cc.Sprite(tyNamespace.notice.Jump_bsc);
                sprite.attr({
                	x: this.backgroundSize.width / 2,
                    y: 200
                });
                background.addChild(sprite);

                this.addTwoMenu();

                break;

            case tyNamespace.JumpType.BxVIP:
                var label = new cc.LabelTTF("只有VIP才能创建房间。", "Arial", 30);
                label.attr({
                	x: this.backgroundSize.width / 2,
                    y: 200
                });
                background.addChild(label);

                this.addTwoMenu();

                break;

            case tyNamespace.JumpType.BxGOLD:
                var label = new cc.LabelTTF("金币不足50万，无法创建房间。", "Arial", 30);
                label.attr({
                	x: this.backgroundSize.width / 2,
                    y: 200
                });
                background.addChild(label);

                this.addTwoMenu();

                break;
        }

//        tyNamespace.PlazaManager.setJumpLayer(this);
    },

    addOneMenu: function () {
    	var confirmItem = new cc.MenuItemImage(gpNamespace.tankuang.queding, gpNamespace.tankuang.queding, this.confirmCallbackFunction, this);
    	var menu = new cc.Menu(confirmItem);
    	menu.attr({
    		x: this.backgroundSize.width / 2,
            y: 55
        });
        this.background.addChild(menu);
    },

    addTwoMenu: function () {
    	var cancelItem = new cc.MenuItemImage(gpNamespace.tankuang.quxiao, gpNamespace.tankuang.quxiao, this.cancelCallbackFunction, this);
    	var confirmItem = new cc.MenuItemImage(gpNamespace.tankuang.queding, gpNamespace.tankuang.queding, this.confirmCallbackFunction, this);

        var menu = new cc.Menu(cancelItem, confirmItem);
        menu.attr({
            x: this.backgroundSize.width / 2,
            y: 70
        });
        menu.alignItemsHorizontallyWithPadding(100);
        this.background.addChild(menu);
    },

    addKickMenu: function () {
    	var kickItem = new cc.MenuItemImage(gpNamespace.tankuang.queding, gpNamespace.tankuang.queding, this.kickCallbackFunction, this);
        var kickMenu = new cc.Menu(kickItem);
        kickMenu.attr({
            x: this.backgroundSize.width / 2,
            y: 55
        });
        this.background.addChild(kickMenu);
    },

    cancelCallbackFunction: function (sender) {
        cc.log("取消");

        tyNamespace.setMenuEnable(sender);

//        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonBack, false);

        this.getParent().removeFromParent(true);
    },

    confirmCallbackFunction: function (sender) {
        cc.log("确定");

        tyNamespace.setMenuEnable(sender);

//        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

        this.callback.apply(this.target);

        this.getParent().removeFromParent(true);
    },

    kickCallbackFunction: function (sender) {
        cc.log("封号");

        tyNamespace.setMenuEnable(sender);

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

        this.callback.apply(this.target);
    },

    setGoodInfo: function () {
        switch (this.type) {
            case tyNamespace.JumpType.MyProp:
                var showContent = "　　" + tyNamespace.JumpInfo.CONTENT;
                var singleLength = 32;

                tyNamespace.SlicedString = [];
                var strArray = tyNamespace.GetSlicedString(showContent, singleLength);

                for (var a = 0; a < strArray.length; a++) {
                    var label = new cc.LabelTTF(strArray[a], "Arial", 25);
                    label.attr({
                        x: 60,
                        y: 210 - 30 * a,
                        anchorX: 0,
                        anchorY: 0
                    });
                    this.background.addChild(label);
                }

                break;

            case tyNamespace.JumpType.MyPropUseable:
                var showContent = "　　" + tyNamespace.JumpInfo.CONTENT;
                var singleLength = 32;

                tyNamespace.SlicedString = [];
                var strArray = tyNamespace.GetSlicedString(showContent, singleLength);

                for (var a = 0; a < strArray.length; a++) {
                    var label = new cc.LabelTTF(strArray[a], "Arial", 25);
                    label.attr({
                        x: 60,
                        y: 180 - 30 * a,
                        anchorX: 0,
                        anchorY: 0
                    });
                    this.background.addChild(label);
                }

                break;

            case tyNamespace.JumpType.ShopSW:
                var showContent = "　　" + tyNamespace.JumpInfo.CONTENT;
                var singleLength = 32;

                tyNamespace.SlicedString = [];
                var strArray = tyNamespace.GetSlicedString(showContent, singleLength);

                for (var a = 0; a < strArray.length; a++) {
                    var label = new cc.LabelTTF(strArray[a], "Arial", 25);
                    label.attr({
                        x: 60,
                        y: 165 - 30 * a,
                        anchorX: 0,
                        anchorY: 0
                    });
                    this.background.addChild(label);
                }

                break;
        }
    }
});

tyNamespace.addJumpLayer = function (type, callback, target, args) {
    var runningScene = cc.director.getRunningScene();
    var modelCancelable = new tyNamespace.ModelLayerCancelable();
    var jumpLayer = new tyNamespace.JumpLayer(type, callback, target, args);
    jumpLayer.setTouchArea(cc.size(524, 310), cc.p(378, 205));
    modelCancelable.addChild(jumpLayer);
    runningScene.addChild(modelCancelable, 105);
};

tyNamespace.addJumpLayerCannotRemove = function (type, callback, target, args) {
    var runningScene = cc.director.getRunningScene();
    var jumpLayer = new tyNamespace.JumpLayer(type, callback, target, args);
    runningScene.addChild(jumpLayer, 105);
};

tyNamespace.WarnLayer = tyNamespace.ModelLayer.extend({
    type: null,
    callback: null,
    target: null,
    args: [],
    background: null,

    ctor: function (type, callback, target, args) {
        this._super();

        this.type = type;
        this.callback = callback;
        this.target = target;
        for (var a = 3; a < arguments.length; a++) {
            this.args.push(arguments[a]);
        }
    },

    onEnter: function () {
        this._super();
        
        //弹出框背景
        var background = new cc.Sprite(gpNamespace.tankuang.pochanbackground);
        background.attr({
            x: cc.winSize.width / 2,
            y: cc.winSize.height / 2
        });
        this.addChild(background);
        this.background = background;
        
        //content
        switch (this.type) {
//            case tyNamespace.WarnType.Gold:
//                var sprite = new cc.Sprite(tyNamespace.notice.Warn_goldInfo);
//                sprite.attr({
//                    x: 340,
//                    y: 220
//                });
//                background.addChild(sprite);
//
//                this.addChargeMenu();
//                break;
//
//            case tyNamespace.WarnType.Diamond:
//                var sprite = new cc.Sprite(tyNamespace.notice.Warn_diamondInfo);
//                sprite.attr({
//                    x: 340,
//                    y: 220
//                });
//                background.addChild(sprite);
//
//                this.addChargeMenu();
//
//                break;
//
//            case tyNamespace.WarnType.Voucher:
//                var sprite = new cc.Sprite(tyNamespace.notice.Warn_voucherInfo);
//                sprite.attr({
//                    x: 340,
//                    y: 220
//                });
//                background.addChild(sprite);
//
//                var item = new cc.MenuItemImage(tyNamespace.notice.Warn_getVoucher, tyNamespace.notice.Warn_getVoucher, this.getVoucherCallbackFunction, this);
//                item.attr({
//                    x: 227 / 2,
//                    y: 32 / 2
//                });
//                var menu = new cc.Menu(item);
//                menu.attr({
//                    x: 170,
//                    y: 140
//                });
//                background.addChild(menu);
//
//                this.addConfirmMenu();
//
//                break;

        case tyNamespace.WarnType.Pochan:
                var info = new cc.Sprite(gpNamespace.warning.Warning_Sentence27);
                info.attr({
                	x: background.getContentSize().width / 2,
                    y: 200
                });
                background.addChild(info);

                this.addPochanMenu();

                break;
        }
    },

    addChargeMenu: function () {
        var chargeItem = new cc.MenuItemImage(tyNamespace.notice.Warn_charge, tyNamespace.notice.Warn_charge, this.chargeCallbackFunction, this);
        var menu = new cc.Menu(chargeItem);
        menu.attr({
            x: 290,
            y: 70
        });
        this.background.addChild(menu);
    },

    addConfirmMenu: function () {
    	var confirmItem = new cc.MenuItemImage(gpNamespace.tankuang.queding, gpNamespace.tankuang.queding, this.confirmCallbackFunction, this);
        var menu = new cc.Menu(confirmItem);
        menu.attr({
            x: 290,
            y: 70
        });
        this.background.addChild(menu);
    },

    addPochanMenu: function () {
    	var buzhuItem = new cc.MenuItemImage(gpNamespace.warning.Warning_GetAllowance, gpNamespace.warning.Warning_GetAllowance, this.buzhuCallbackFunction, this);
    	var chargeItem = new cc.MenuItemImage(gpNamespace.warning.Warning_INeedCharge, gpNamespace.warning.Warning_INeedCharge, this.chargeCallbackFunction, this);
        var menu = new cc.Menu(buzhuItem, chargeItem);
        menu.attr({
            x: 290,
            y: 55
        });
        menu.alignItemsHorizontallyWithPadding(100);
        this.background.addChild(menu);
    },

    getVoucherCallbackFunction: function (sender) {
        cc.log("获取兑换券");

        tyNamespace.setMenuEnable(sender);

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

        var runningScene = cc.director.getRunningScene();
        var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
        var modelLayer = new tyNamespace.ModelLayer();
        modelLayer.setTouchArea(cc.size(900, 445), cc.p(190, 138));
        modelLayerCancelable.addChild(modelLayer);
        runningScene.addChild(modelLayerCancelable, 105);

        var getVoucherLayer = new tyNamespace.GetVoucherLayer();
        getVoucherLayer.attr({
            x: 0,
            y: cc.winSize.height
        });
        modelLayer.addChild(getVoucherLayer);

        tyNamespace.AnimationManager.nodeJumpShow(getVoucherLayer, -cc.winSize.height);
    },

    chargeCallbackFunction: function (sender) {
        cc.log("充值");

        tyNamespace.setMenuEnable(sender);

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

        this.callback.apply(this.target, this.args);
    },

    confirmCallbackFunction: function (sender) {
        cc.log("确定");

        tyNamespace.setMenuEnable(sender);

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

        this.getParent().removeFromParent(true);
    },

    buzhuCallbackFunction: function (sender) {
        cc.log("领取补助");

        tyNamespace.setMenuEnable(sender);

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonPochanEffect, false);

        tyNamespace.addWaitLayer();
        xinyou.netManager.getPochanGold();

        this.getParent().removeFromParent(true);
    }
});

tyNamespace.addWarnLayer = function (type, callback, target, args) {
    var runningScene = cc.director.getRunningScene();
    var modelCancelable = new tyNamespace.ModelLayerCancelable();
    var warnLayer = new tyNamespace.WarnLayer(type, callback, target, args);
    warnLayer.setTouchArea(cc.size(524, 310), cc.p(378, 205));
    modelCancelable.addChild(warnLayer);
    runningScene.addChild(modelCancelable, 105);
};


tyNamespace.GetVoucherLayer = cc.Layer.extend({
    onEnter: function () {
        this._super();

        //弹出框背景
        var background = new cc.Sprite(tyNamespace.notice.Warn_infoBackground);
        background.attr({
            x: cc.winSize.width / 2,
            y: cc.winSize.height / 2
        });
        this.addChild(background);

        //弹出内容
        var sprite = new cc.Sprite(tyNamespace.notice.Warn_infoContent);
        sprite.attr({
            x: 450,
            y: 280
        });
        background.addChild(sprite);

        //返回
        var item = new cc.MenuItemImage(tyNamespace.notice.Warn_back, tyNamespace.notice.Warn_back, this.backCallbackFunction, this);
        item.attr({
            x: 183 / 2,
            y: 74 / 2
        });
        var menu = new cc.Menu(item);
        menu.attr({
            x: 360,
            y: 40
        });
        background.addChild(menu);
    },

    backCallbackFunction: function (sender) {
        cc.log("返回");

        tyNamespace.setMenuEnable(sender);

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonBack, false);

        this.getParent().getParent().removeFromParent(true);
    }
});


tyNamespace.BuyLayer = tyNamespace.ModelLayer.extend({
    priceType: null,
    missionType: null,
    target: null,
    args: [],

    background: null,
    goldBackground: null,
    diamondBackground: null,
    voucherBackground: null,

    goodID: null,
    singlePrice: null,
    goodCount: null,
    priceCount: null,

    goodQuantity: null,
    goodPrice: null,

    ctor: function (priceType, missionType, target, args) {
        this._super();

        this.priceType = priceType;
        this.missionType = missionType;
        this.target = target;
        if (args != undefined) {
            this.args = args;

            this.goodID = args[0];
            this.singlePrice = args[1];
            this.goodCount = 1;
            this.priceCount = this.singlePrice * this.goodCount;
        }
    },

    onEnter: function () {
        this._super();

        //弹出框背景
        var background = new cc.Sprite(tyNamespace.notice.Buy_background);
        background.attr({
            x: cc.winSize.width / 2,
            y: cc.winSize.height / 2
        });
        this.addChild(background);
        this.background = background;

        //关闭
        var closeItem = new cc.MenuItemImage(tyNamespace.ty.Xzgb_close, tyNamespace.ty.Xzgb_close, this.closeCallbackFunction, this);
        closeItem.attr({
            x: 94 / 2,
            y: 95 / 2
        });
        var closeMenu = new cc.Menu(closeItem);
        closeMenu.attr({
            x: 540,
            y: 385
        });
        background.addChild(closeMenu);

        //弹出框标题
        var title = new cc.Sprite(tyNamespace.notice.Buy_title);
        title.attr({
            x: 59,
            y: 368,
            anchorX: 0,
            anchorY: 0
        });
        background.addChild(title);

        //购买数量
        var buyCount = new cc.Sprite(tyNamespace.notice.Buy_label);
        buyCount.attr({
            x: 58,
            y: 146,
            anchorX: 0,
            anchorY: 0
        });
        background.addChild(buyCount);

        //最小值
        var minItem = new cc.MenuItemImage(tyNamespace.notice.Buy_min, tyNamespace.notice.Buy_min, this.minCallbackFunction, this);
        minItem.attr({
            x: 62 / 2,
            y: 76 / 2
        });
        var minMenu = new cc.Menu(minItem);
        minMenu.attr({
            x: 201,
            y: 120
        });
        background.addChild(minMenu);

        //减一
        var minusItem = new cc.MenuItemImage(tyNamespace.notice.Buy_minus, tyNamespace.notice.Buy_minus, this.minusCallbackFunction, this);
        minusItem.attr({
            x: 62 / 2,
            y: 76 / 2
        });
        var minusMenu = new cc.Menu(minusItem);
        minusMenu.attr({
            x: 263,
            y: 120
        });
        background.addChild(minusMenu);

        //数量背景
        var countBackground = new cc.Sprite(tyNamespace.notice.Buy_countBackground);
        countBackground.attr({
            x: 318,
            y: 136,
            anchorX: 0,
            anchorY: 0
        });
        background.addChild(countBackground);

        //默认数量为1
        var count = new cc.LabelTTF(this.goodCount.toString(), "Arial", 25);
        count.attr({
            x: 72,
            y: 22
        });
        countBackground.addChild(count);
        this.goodQuantity = count;

        //加一
        var plusItem = new cc.MenuItemImage(tyNamespace.notice.Buy_plus, tyNamespace.notice.Buy_plus, this.plusCallbackFunction, this);
        plusItem.attr({
            x: 62 / 2,
            y: 76 / 2
        });
        var plusMenu = new cc.Menu(plusItem);
        plusMenu.attr({
            x: 454,
            y: 120
        });
        background.addChild(plusMenu);

        //最大值
        var maxItem = new cc.MenuItemImage(tyNamespace.notice.Buy_max, tyNamespace.notice.Buy_max, this.maxCallbackFunction, this);
        maxItem.attr({
            x: 62 / 2,
            y: 76 / 2
        });
        var maxMenu = new cc.Menu(maxItem);
        maxMenu.attr({
            x: 516,
            y: 120
        });
        background.addChild(maxMenu);

        switch (this.priceType) {
            case tyNamespace.PriceType.Gold:
                //金币背景
                var goldBackground = new cc.Sprite(tyNamespace.notice.Buy_gold);
                goldBackground.attr({
                    x: 65,
                    y: 44,
                    anchorX: 0,
                    anchorY: 0
                });
                background.addChild(goldBackground);
                break;

            case tyNamespace.PriceType.Diamond:
                //钻石背景
                var diamondBackground = new cc.Sprite(tyNamespace.notice.Buy_diamond);
                diamondBackground.attr({
                    x: 65,
                    y: 46,
                    anchorX: 0,
                    anchorY: 0
                });
                background.addChild(diamondBackground);
                break;

            case tyNamespace.PriceType.Voucher:
                //兑换券背景
                var voucherBackground = new cc.Sprite(tyNamespace.notice.Buy_voucher);
                voucherBackground.attr({
                    x: 65,
                    y: 50,
                    anchorX: 0,
                    anchorY: 0
                });
                background.addChild(voucherBackground);
                break;
        }

        //商品价格
        var goodPrice = new cc.LabelTTF(this.priceCount.toString(), "Arial", 25);
        goodPrice.attr({
            x: 194,
            y: 73
        });
        background.addChild(goodPrice);
        this.goodPrice = goodPrice;

        //购买
        var buyItem = new cc.MenuItemImage(tyNamespace.notice.Buy_buy, tyNamespace.notice.Buy_buy, this.buyCallbackFunction, this);
        buyItem.attr({
            x: 140 / 2,
            y: 84 / 2
        });
        var buyMenu = new cc.Menu(buyItem);
        buyMenu.attr({
            x: 383,
            y: 30
        });
        background.addChild(buyMenu);

        tyNamespace.PlazaManager.setBuyLayer(this);
    },

    closeCallbackFunction: function (sender) {
        cc.log("关闭");

        tyNamespace.setMenuEnable(sender);

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonClose, false);

        this.getParent().removeFromParent(true);
    },

    minCallbackFunction: function (sender) {
        cc.log("最小值");

        tyNamespace.setMenuEnable(sender);

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

        this.goodQuantity.setString("1");
        this.goodPrice.setString((this.singlePrice * 1).toString());
    },

    minusCallbackFunction: function () {
        cc.log("当前值减一");

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

        var currentQuantity = parseInt(this.goodQuantity.getString()) - 1;
        if (currentQuantity <= 0)
            currentQuantity = 1;
        this.goodQuantity.setString(currentQuantity.toString());
        this.goodPrice.setString((this.singlePrice * currentQuantity).toString());
    },

    plusCallbackFunction: function () {
        cc.log("当前值加一");

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

        var currentQuantity = parseInt(this.goodQuantity.getString()) + 1;
        if (currentQuantity >= 100)
            currentQuantity = 99;
        this.goodQuantity.setString(currentQuantity.toString());
        this.goodPrice.setString((this.singlePrice * currentQuantity).toString());
    },

    maxCallbackFunction: function (sender) {
        cc.log("最大值");

        tyNamespace.setMenuEnable(sender);

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

        this.goodQuantity.setString("99");
        this.goodPrice.setString((this.singlePrice * 99).toString());
    },

    buyCallbackFunction: function (sender) {
        cc.log("购买");

        tyNamespace.setMenuEnable(sender);

        gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

        var currentQuantity = parseInt(this.goodQuantity.getString());

        tyNamespace.addWaitLayer();

        switch (this.missionType) {
            case tyNamespace.MissionType.Gold:
                xinyou.netManager.buyGoodsJb(this.goodID, currentQuantity);
                break;

            case tyNamespace.MissionType.Prop:
                tyNamespace.buyPropFrom = tyNamespace.BuyPropFrom.Shop;
                xinyou.netManager.buyGoodsDj(this.goodID, currentQuantity);
                break;
        }

        this.getParent().removeFromParent(true);
    },

    setGoodInfo: function () {
        var showContent = "　　" + tyNamespace.BuyInfo.CONTENT;
        var singleLength = 32;

        tyNamespace.SlicedString = [];
        var strArray = tyNamespace.GetSlicedString(showContent, singleLength);

        for (var a = 0; a < strArray.length; a++) {
            var label = new cc.LabelTTF(strArray[a], "Arial", 25);
            label.attr({
                x: 100,
                y: 300 - 30 * a,
                anchorX: 0,
                anchorY: 0
            });
            this.background.addChild(label);
        }
    }
});

tyNamespace.addBuyLayer = function (priceType, missionType, target, args) {
    var runningScene = cc.director.getRunningScene();
    var modelCancelable = new tyNamespace.ModelLayerCancelable();
    var buyLayer = new tyNamespace.BuyLayer(priceType, missionType, target, args);
    buyLayer.setTouchArea(cc.size(605, 450), cc.p(338, 135));
    modelCancelable.addChild(buyLayer);
    runningScene.addChild(modelCancelable, 105);
};


tyNamespace.JumpWithSpriteRemove = cc.Layer.extend({
    jumpMoveSize: null,
    backgroundName: null,
    spriteName: null,

    ctor: function (backgroundName, spriteName) {
        this._super();

        this.backgroundName = backgroundName;
        this.spriteName = spriteName;
    },

    onEnter: function () {
        this._super();

        //背景
        var background = new cc.Sprite(this.backgroundName);
        background.attr({
            x: cc.winSize.width / 2,
            y: cc.winSize.height + background.getContentSize().height / 2
        });
        this.jumpMoveSize = background.getContentSize().height;
        this.addChild(background);

        //info
        var info = new cc.Sprite(this.spriteName);
        info.attr({
            x: background.getContentSize().width / 2,
            y: background.getContentSize().height / 2
        });
        background.addChild(info);
    },

    onEnterTransitionDidFinish: function () {
        this._super();

        var self = this;

        this.runAction(cc.moveBy(1, cc.p(0, -this.jumpMoveSize)).easing(cc.easeSineOut()));

        this.schedule(function () {
            this.runAction(cc.sequence(cc.moveBy(1, cc.p(0, this.jumpMoveSize)).easing(cc.easeSineIn()), cc.callFunc(function () {
                self && self.getParent().removeFromParent(true);
            })));
        }, 5);
    }
});

tyNamespace.addSpriteRemoveLayer = function (backgroundName, spriteName) {
    var runningScene = cc.director.getRunningScene();
    var modelCancelable = new tyNamespace.ModelLayerCancelable(1);
    var jumpWithSpriteRemove = new tyNamespace.JumpWithSpriteRemove(backgroundName, spriteName);
    modelCancelable.addChild(jumpWithSpriteRemove);
    runningScene.addChild(modelCancelable, 100);
};

tyNamespace.JumpWithTextRemoved = cc.Layer.extend({
    str: null,
    offsetY: null,

    ctor: function (str, offsetY) {
        this._super();

        this.str = str;

        if (offsetY != undefined) {
            this.offsetY = offsetY;
        }
        else {
            this.offsetY = 0;
        }
    },

    onEnter: function () {
    	this._super();
        //背景
        cc.log("is ok1");
        var background = new cc.Sprite(gpNamespace.dj.UseDjBg);
        cc.log("is ok2");
        background.attr({
            x: 640,
            y: 360 + this.offsetY
        });
        this.addChild(background);

        var label = new cc.LabelTTF(this.str, "Arial", 25);
        label.setFontFillColor(cc.color(100, 6, 6, 255));
        label.attr({
            x: background.getContentSize().width / 2,
            y: background.getContentSize().height / 2
        });
        background.addChild(label);
    },

    onEnterTransitionDidFinish: function () {
        this._super();

        this.scheduleOnce(function () {
            this.getParent().removeFromParent(true);
        }, 2)
    }
});

tyNamespace.addTextRemoveLayer = function (str, offsetY) {
	cc.log("addTextRemoveLayer");
	var runningScene = cc.director.getRunningScene();
    
    var modelCancelable = new tyNamespace.ModelLayerCancelable(1);
    var jumpWithTextRemoved = new tyNamespace.JumpWithTextRemoved(str, offsetY);
    modelCancelable.addChild(jumpWithTextRemoved);
    runningScene.addChild(modelCancelable, 100);
};